package org.devops  
  
class ServiceTemplate {
    static String Generate(String SERVICE_NAME,String DEPLOYMENT_REPLICAS,String IMAGE_TAG,String LIMITS_CPU,String LIMITS_MEM,String REQUESTS_CPU,String REQUESTS_MEM) {
        return """
        ---
        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: ${SERVICE_NAME}
          namespace: devops
        spec:
          replicas: ${DEPLOYMENT_REPLICAS}
          selector:
            matchLabels:
              app: ${SERVICE_NAME}
          template:
            metadata:
              labels:
                app: ${SERVICE_NAME}
            spec:
              containers:
                - name: ${SERVICE_NAME}
                  image: godocker.com/devops/${IMAGE_TAG}
                  imagePullPolicy: Always
                  ports:
                    - containerPort: 80
                  resources:
                    limits:
                      cpu: ${LIMITS_CPU}
                      memory: ${LIMITS_MEM}
                    requests:
                      cpu: ${REQUESTS_CPU}
                      memory: ${REQUESTS_MEM}

        ---

        apiVersion: v1
        kind: Service
        metadata:
          name: ${SERVICE_NAME}
          namespace: devops
        spec:
          selector:
            app: ${SERVICE_NAME}
          ports:
            - protocol: TCP
              port: 80
              targetPort: 80
        """.stripIndent()
    }
}
